/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlets;

import Utils.Product;
import Utils.dbManager;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.swing.JLabel;

/**
 *
 * @author Alice
 */
public class SellerProdottoInDataBase extends HttpServlet {
      private dbManager manager;
   
    @Override
public void init() throws ServletException {
// inizializza il DBManager dagli attributi di Application
this.manager = (dbManager)super.getServletContext().getAttribute("dbmanager");
}
  
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, NumberFormatException {
           
        HttpSession session = request.getSession(false);

        try{   
      
            String seller= request.getParameter("seller");
        String product= request.getParameter("product");
        String q= request.getParameter("quantity");
        int quantity=Integer.parseInt(q);
        String category= request.getParameter("combobox");
        String um= request.getParameter("um");
        String p= request.getParameter("price");
        float price=Float.parseFloat(p);
   
       // if(quantity!=Integer)
      
    
        if(session.getAttribute("seller")==null)
            response.sendRedirect(request.getContextPath() + "/ErrorLoginServlet");
        
        String username=(String)session.getAttribute("username");
        
    if (session == null) {
    response.sendRedirect(request.getContextPath()+ "/ErrorLoginServlet");
    } else {
       
   //CONTROLLO DATI
     //int sel=Integer.parseInt(seller);
        
   Date d=new Date();
   Timestamp t=new Timestamp(d.getTime());
   

        List<Product> productSeller = manager.upProductsSeller(seller,product,quantity,category,um,price,t);
        session.setAttribute("products", product);
        String mex ="Prodotto aggiunto!";
        session.setAttribute("confirm", mex);
        response.sendRedirect(request.getContextPath()+ "/SellerLandingServlet");

     
    } }catch (SQLException ex) {
     //throw new ServletException(ex);
        session.setAttribute("problema", "si");
        response.sendRedirect(request.getContextPath()+ "/SellerLandingServlet");

    } 
    }

    
}
